<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Asset Manager
 *
 * Software to automatically manage how assets are delivered on a website
 *
 * @package		Asset Manager
 * @author		Adam Lewis <adam.lewis@bestservedcold.com>
 * @copyright	Copyright (c) 2006 - 2012, Best Served Cold Media Limited.
 * @license		http://bestservedcold.com/license.html
 * @link		http://bestservedcold.com
 * @since		Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * Single Query Assets Library
 *
 * The Asset library simply checks the asset database and returns the asset location.  If the asset
 * is not in the database, then it calls the asset library and queues the asset for processing.
 *
 * @package		Asset Manager
 * @subpackage	Assets
 * @category	Libraries
 * @author  	Adam Lewis <adam.lewis@bestservedcold.com>
 * @since		2012-05-22
 */
class Am_optimize_html {
	public function output($output)
	{
		return preg_replace(
		'%# Collapse whitespace everywhere but in blacklisted elements.
		(?>				# Match all whitespans other than single space.
			[^\S ]\s*	# Either one [\t\r\n\f\v] and zero or more ws,
			| \s{2,}	# or two or more consecutive-any-whitespace.
		)				# Note: The remaining regex consumes no text at all...
		(?=				# Ensure we are not in a blacklist tag.
			[^<]*+		# Either zero or more non-"<" {normal*}
			(?:			# Begin {(special normal*)*} construct
			<			# or a < starting a non-blacklist tag.
			(?!/?(?:textarea|pre|script)\b)
			[^<]*+		# more non-"<" {normal*}
			)*+			# Finish "unrolling-the-loop"
		(?:			# Begin alternation group.
			<			# Either a blacklist start tag.
			(?>textarea|pre|script)\b
			| \z		# or end of file.
		)				# End alternation group.
		)				# If we made it here, we are not in a blacklist tag.
		%Six', " ", $output);
	}
}
